home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / thrust-s.53 / thrust-s / thrust / src / font5x5.c < prev    next >
C/C++ Source or Header  |  1995-10-12  |  3KB  |  177 lines

  1.  
  2. /* Written by Peter Ekberg, peda@lysator.liu.se */
  3.  
  4. #include <vgagl.h>
  5. #include <vga.h>
  6. #include <unistd.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include "thrust.h"
  10.  
  11. byte chcolor=20;
  12. byte chpaper=0;
  13. byte chflag=0;
  14.  
  15. void
  16. printgc(word offset, byte ch)
  17. {
  18.   int x;
  19.   int y;
  20.   char width = font[ch][0];
  21.   byte bits=1<<(width-1);
  22.   byte bit=bits;
  23.  
  24.   for(y=1; y<6; y++, bit=bits) {
  25.     for(x=0; x<width; x++, bit>>=1) {
  26.       if(font[ch][y] & bit)
  27.     *(graph_mem+offset+x) = chcolor;
  28.       else if(chflag)
  29.     *(graph_mem+offset+x) = chpaper;
  30.     }
  31.     if(chflag)
  32.       *(graph_mem+offset+x) = chpaper;
  33.     offset+=320;
  34.   }
  35. }
  36.  
  37. int
  38. printgs(int x, int y, char *string)
  39. {
  40.   byte i;
  41.   byte len=strlen(string);
  42.   byte ch;
  43.   word offset=x+320*y;
  44.   char xc;
  45.   int ox=x;
  46.  
  47.   for(i=0; i<len; i++)
  48.     if((ch=*(string+i)) < 96)
  49.       switch(ch)
  50.     {
  51.     case 10:
  52.       y+=6;
  53.       offset += 1920;
  54.       break;
  55.     case 13:
  56.       offset = (x=ox)+320*y;
  57.       break;
  58.     default:
  59.       printgc(offset,ch);
  60.       offset += (xc=font[ch][0]+1);
  61.       x += xc;
  62.     }
  63.   return(x);
  64. }
  65.  
  66. int
  67. readgs(int x, int y, char string[], int maxc, int maxp, char flag)
  68. {
  69.   int xc;
  70.   word offset;
  71.   word offsetcursor;
  72.   int i,j;
  73.   int key;
  74.   byte ch;
  75.   byte temp=chcolor;
  76.   int leftx=x;
  77.   byte cursor=0;
  78.  
  79.   maxp+=x;
  80.   i=strlen(string);
  81.   for(j=0; j<i; j++)
  82.     string[j] = toupper(string[j]);
  83.   x=printgs(x,y,string);
  84.   offset=x+y*320;
  85.  
  86.   do {
  87.     do {
  88.       key=0;
  89.       cursor=1-cursor;
  90.       for(j=0; j<12 && !key; j++) {
  91.     key=vga_getkey();
  92.     if(!key)
  93.       usleep(25000L);
  94.       }
  95.       vga_lockvc();
  96.       for(offsetcursor=offset+320*5, j=0; j<5; offsetcursor++, j++)
  97.     *(graph_mem+offsetcursor)=cursor*temp;
  98.       vga_unlockvc();
  99.     } while(!key);
  100.     vga_lockvc();
  101.     for(offsetcursor=offset+320*5, j=0; j<5; offsetcursor++, j++)
  102.       *(graph_mem+offsetcursor)=chpaper;
  103.     vga_unlockvc();
  104.  
  105.     ch=toupper(key);
  106.     switch(ch) {
  107.     case 10:
  108.       string[i]=0;
  109.       ch=27;
  110.       break;
  111.     case 27:
  112.       x=-1;
  113.       break;
  114.     case 127:
  115.       if(i) {
  116.     offset -= (xc=1+font[(int)string[--i]][0]);
  117.     x -= xc;
  118.     chcolor=chpaper;
  119.     vga_lockvc();
  120.     printgc(offset,string[i]);
  121.     vga_unlockvc();
  122.     chcolor=temp;
  123.       }
  124.       break;
  125.     default:
  126.       if(!font[ch][0]) {
  127.     printf("\007");
  128.     fflush(stdout);
  129.       }
  130.       else if(i!=maxc && x+(xc=1+font[ch][0])<=maxp) {
  131.     string[i++]=ch;
  132.     vga_lockvc();
  133.     printgc(offset,ch);
  134.     vga_unlockvc();
  135.     offset+=xc;
  136.     x+=xc;
  137.       }
  138.     }
  139.   }
  140.   while(ch!=27);
  141.  
  142.   if(flag) {
  143.     vga_lockvc();
  144.     for(i=y; i<y+5; i++)
  145.       for(xc=leftx; xc<maxp; xc++)
  146.     *(graph_mem+xc+320*i)=chpaper;
  147.     vga_unlockvc();
  148.   }
  149.  
  150.   return(x);
  151. }
  152.  
  153. int
  154. gstrlen(char *string)
  155. {
  156.   int len=strlen(string);
  157.   int width=0;
  158.   int count=0;
  159.   int i;
  160.   byte ch;
  161.  
  162.   for(i=0; i<len; i++)
  163.     if((ch=*(string+i)) < 96)
  164.       switch(ch) {
  165.       case 13:
  166.       case 10:
  167.     if(count>width)
  168.       width=count;
  169.     count=0;
  170.     break;
  171.       default:
  172.     count += font[ch][0]+1;
  173.       }
  174.  
  175.   return((count>width) ? count : width);
  176. }
  177.